
/* 
@title: The_Legend_of_Zelda-Links_Escape
@description: The game "The Legend of Zelda: Link's Escape" by ItzHex is a thematic escape adventure inspired by the classic Zelda series. The player assumes the role of Link as he navigates through levels filled with enemies such as Moblins and Lynels.
@author: ItzHex
@tags: []
@addedOn: 2023-08-28
*/


// let t1 = 1
// let t2 = 2
// let t3 = 3
// let t4 = 4
// let t5 = 5
// let t6 = 6
// let t7 = 7
// let t8 = 8
// let t9 = 9
// let tm = 1
// UNCOMMENT THE ABOVE VARIABLES AND COMMENT OUT THE BELOW VARIABLES TO QUICKLY TEST OUT THE CASTLE MOVEMENT AND BOSS FIGHT
let t1 = 4
let t2 = 8
let t3 = 12
let t4 = 16
let t5 = 20
let t6 = 24
let t7 = 28
let t8 = 32
let t9 = 36
let tm = 4





const player = "p"

const ground = "g"

const sky = "z"

const moblin = "r"

const lynel = "l"

const bg0 = "0"
const bg1 = "1"
const bg2 = "2"
const bg3 = "3"
const bg4 = "4"
const bg5 = "5"
const bg6 = "6"
const bg7 = "7"
const bg8 = "8"
const bg9 = "9"
const bg10 = "a"
const bg11 = "b"
const bg12 = "v"
const bg13 = "d"
const bg14 = "c"
const bg15 = "f"
const bg16 = "h"
const bg17 = "i"
const bg18 = "j"
const bg19 = "k"
const bg20 = "m"
const bg21 = "n"
const bg22 = "o"
const bg23 = "q"
const bg24 = "t"

const house1 = "e"
const house2 = "y"
const house3 = "x"
const house4 = "w"

var gameRunning = false;

var titlescreen = true;

var score = 0;

var isReady = false;

var isJumping = false;

var animCount = 0;

var speed = 1;

var multiplier = 1;

var enemyShouldJump = 20;

var canJump = true;

var inAir = false;

var lastJumped = false;

let isEndGame = false;

let direction = -1;

var mPart1 = tune`
125: A4^125,
1250,
125: A4^125,
125: A4^125,
125: A4^125,
125,
125: A4^125,
125: A4^125,
250,
125: G4^125,
125: A4^125,
750,
125: A4^125,
125: A4^125,
125: A4^125,
125,
125: A4^125`;
var mPart2 = tune`
125: A4^125,
250,
125: G4^125,
125: A4^125,
750,
125: A4^125,
125: A4^125,
125: A4^125,
125,
125: A4^125,
125: A4^125,
125,
125: E4^125,
125: E4^125,
125: E4^125,
125,
125: E4^125,
125: E4^125,
125: E4^125,
125,
125: E4^125,
125: E4^125,
125: E4^125,
125,
125: E4^125,
125`;
var mPart3 = tune`
125: A4^125,
375,
125: E4^125,
625,
125: A4^125,
125,
125: A4^125,
125: B4^125,
125: C5^125,
125: D5^125,
125: E5^125,
1125,
125: E5^125,
125,
125: E5^125,
125: F5^125,
125,
125: G5^125`;
var mPart4 = tune`
125: A5^125,
1125,
125: A5^125,
125,
125: A5^125,
125: G5^125,
125,
125: F5^125,
125: G5^125,
250,
125: F5^125,
125: E5^125,
875,
125: E5^125,
375`;
var mPart5 = tune`
125: D5^125,
125,
125: D5^125,
125: E5^125,
125: F5^125,
875,
125: E5^125,
125,
125: D5^125,
125,
125: C5^125,
125,
125: C5^125,
125: D5^125,
125: E5^125,
875,
125: D5^125,
125,
125: C5^125,
125`;
var mPart6 = tune`
125: B4^125,
125,
125: B4^125,
125: C5^125,
125: D5^125,
875,
125: F5^125,
375,
125: E5^125,
125,
125: E4^125,
125: E4^125,
125: E4^125,
125,
125: E4^125,
125: E4^125,
125: E4^125,
125,
125: E4^125,
125: E4^125,
125: E4^125,
125,
125: E4^125,
125`;

var bPart1 = tune`
125: A4~125 + E4~125,
375,
125: A4~125 + E4~125,
375,
125: A4~125 + E4~125,
375,
125: A4~125 + E4~125,
375,
125: G4~125 + D4~125,
375,
125: G4~125 + D4~125,
375,
125: G4~125 + D4~125,
375,
125: G4~125 + D4~125,
375`;
var bPart2 = tune`
125: C4~125 + F4~125,
375,
125: F4~125 + C4~125,
375,
125: F4~125 + C4~125,
375,
125: F4~125 + C4~125,
375,
125: E4~125 + C4~125,
375,
125: E4~125 + C4~125,
375,
125: E4~125 + C4~125,
375,
125: E4~125 + C4~125,
375`;
var bPart3 = tune`
125: A4~125 + E4~125,
375,
125: A4~125 + E4~125,
375,
125: A4~125 + E4~125,
375,
125: A4~125 + E4~125,
375,
125: G4~125 + D4~125,
375,
125: G4~125 + D4~125,
375,
125: G4~125 + D4~125,
375,
125: G4~125 + D4~125,
375`;
var bPart4 = tune`
125: C4~125 + F4~125,
375,
125: F4~125 + C4~125,
375,
125: F4~125 + C4~125,
375,
125: F4~125 + C4~125,
375,
125: G4~125 + E4~125,
375,
125: G4~125 + E4~125,
375,
125: G4~125 + E4~125,
375,
125: G4~125 + E4~125,
375`;
var bPart5 = tune`
125: D4~125 + F4~125,
375,
125: F4~125 + D4~125,
375,
125: F4~125 + D4~125,
375,
125: F4~125 + D4~125,
375,
125: E4~125 + C4~125,
375,
125: E4~125 + C4~125,
375,
125: E4~125 + C4~125,
375,
125: E4~125 + C4~125,
375`;
var bPart6 = tune`
125: D4~125 + C4~125,
375,
125: D4~125 + C4~125,
375,
125: D4~125 + C4~125,
375,
125: D4~125 + C4~125,
375,
125: C4~125 + E4~125,
375,
125: C4~125 + E4~125,
375,
125: C4~125 + E4~125,
375,
125: C4~125 + E4~125,
375`;

async function playMusic() {
  playTune(mPart1);
  playTune(bPart1);
  setTimeout(() => {
    playTune(mPart2);
    playTune(bPart2);
    setTimeout(musicLoop, 4000);
  }, 4000);
}

async function musicLoop() {
  playTune(mPart3);
  playTune(bPart3);
  setTimeout(() => {
    playTune(mPart4);
    playTune(bPart4);
    setTimeout(() => {
      playTune(mPart5);
      playTune(bPart5);
      setTimeout(() => {
        playTune(mPart6);
        playTune(bPart6);
        setTimeout(musicLoop, 4000);
      }, 4000);
    }, 4000);
  }, 4000);
}

setLegend(
  [ player, bitmap`
....00000.......
...04442500.....
..0442240220....
.0440440224000..
0440200224000...
04402404000.....
.040220020200...
..00220220220...
...042022240....
...00404440.....
...04000000.....
..044022040.....
..044022020.....
..000000040.....
...02222000.....
..0000000000....` ],
  [ ground, bitmap`
CCC09009CC0090CC
CCCC009CCCCC0009
CCCC009CCCCC00C0
9CCC009CCCCCC0C0
9CCC09CCCCCCC0C0
CCCC09CCCCCCCCC0
CCCC09CCCCC99009
CCCC09CCCC9CCC09
CCC009CCCC9CCCC0
CCC009CCCC9CCCC0
9C00090CC09CCC00
9C099900C09CCC09
C09CCCCC009CCC09
C09CCCC0009CCC09
C9CCCCCC000CC000
09C9CC9090099009`],
  [ sky, bitmap`
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777`],
  [ moblin, bitmap`
.....99999......
...939999.......
..9329993333....
.332299993333...
.9999999933333..
33929999333333..
993299939993333.
999939939993332.
.99999333999223.
.99999339999333.
..9222229992222.
..9933333993333.
....333333333399
....3333339993..
..999333999999..
...9999..99999..`],
  [ lynel, bitmap`
.....33339333...
....3233993.....
....92939933....
....999393......
....3999933.....
.222239999.....3
22222399993...33
.222239993333333
....33333333333.
....33333333333.
...33333333333..
..3333333333333.
..33333333333333
...333222222333.
....3........3..
................`],
  [ bg0, bitmap`
................
................
................
................
................
...............0
.............000
............0000
...........00000
..........000000
........00000000
.......000000000
.....00000000000
...0000000000000
0000000000000000
0000000000000000`],
  [ bg1, bitmap`
...0000000000000
...0000000000000
..00000000000000
.000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ bg2, bitmap`
................
................
................
...........000..
..........00000.
..........000000
..........000000
.........0000000
.........0000000
........00000000
.......000000000
.......000000000
......0000000000
.....00000000000
.....00000000000
....000000000000`],
  [ bg3, bitmap`
................
................
................
................
................
................
0...............
00..............
0000............
000000..........
00000000........
0000000000......
000000000000....
00000000000000..
0000000000000000
0000000000000000`],
  [ bg4, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ bg5, bitmap`
................
................
................
................
................
................
................
................
................
................
................
................
................
...........00...
...........00...
00........0000..`],
  [ bg6, bitmap`
000.......00000.
0000......000000
00000....0000000
000000...0000000
0000000.00000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ bg7, bitmap`
................
................
................
.....0..........
....000.........
....000.........
....000.........
....000.........
....000.........
....000.........
....000.........
....000.........
....000.........
....000.000...00
....000.000...00
....000.000...00`],
  [ bg8, bitmap`
....000.000...00
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
...0000000000000
...0000000000000`],
  [ bg9, bitmap`
...0000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ bg10, bitmap`
................
..............00
..............00
..............00
..............00
..............00
...........00000
...........00000
...........00000
...........00000
...........00000
...........00000
...........00000
...........00000
.............000
.............000`],
  [ bg11, bitmap`
.............000
...............0
...............0
...............0
................
................
...0............
...0............
...0............
...0............
...0..0..0..0...
...0..00.00.00..
...0..00.00.00..
...0000000000000
..00000000000000
.000000000000000`],
  [ bg12, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
.000000000000000
.000000000000000
..00000000000000
..00000000000000
..00000000000000
..00000000000000
0.00000000000000
0.00000000000000
0.00000000000000`],
  [ bg13, bitmap`
0.00000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ bg14, bitmap`
................
................
................
................
................
................
................
................
................
................
................
................
................
.....0..........
.....0..........
.....0..........`],
  [ bg15, bitmap`
....000.........
....000.........
....000.........
....000.........
....000.........
....000.........
..0000000.......
..0000000.......
..0000000.......
..0000000.......
..0000000.......
00000000000.....
00000000000.....
00000000000.....
00000000000.....
00000000000.....`],
  [ bg16, bitmap`
00000000000.....
0000000000000...
0000000000000...
0000000000000...
0000000000000...
0000000000000...
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ bg17, bitmap`
00000000000000..
000000000000....
000000000000....
000000000000....
.000000000......
.000000000......
.000000000......
.000000000......
.000000000......
.000000000...0..
.000000000..00.0
.000000000..00.0
.000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ bg18, bitmap`
................
................
................
................
................
......00........
......00........
......00........
......00........
0..0..00........
0.00..00........
0.00..00........
00000000........
000000000.......
0000000000......
00000000000.....`],
  [ bg19, bitmap`
00000000000.....
00000000000.....
00000000000.....
00000000000.....
00000000000.....
00000000000.....
0000000000......
0000000000......
000000000.......
000000000.......
000000000.......
000000000.......
000000000.000...
000000000.000...
000000000.000...
000000000.000...`],
  [ bg20, bitmap`
................
................
................
.....0..........
....000.........
....000.........
....000.........
....000.........
....000.........
....000.........
....000.........
....000.........
000.000.........
000.000.........
000.000.........
000.000.........`],
  [ bg21, bitmap`
0000000.........
0000000.........
0000000.........
0000000.........
0000000.........
0000000.........
0000000.........
0000000.........
0000000.........
0000000.........
0000000.........
0000000.........
0000000.......0.
00000000......0.
00000000.....00.
00000000....0000`],
  [ bg22, bitmap`
0.............00
00...........000
00..........0000
000....000000000
0000..0000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ bg23, bitmap`
00..............
000.............
000.............
0000............
00000......00...
000000....0000..
000000000000000.
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ bg24, bitmap`
................
................
................
................
................
................
................
................
................
0...............
00..............
000.............
0000............
00000...........
00000...........
000000..........`],
  [ house1, bitmap`
..........000000
.........0333333
.........0333333
........03333333
........03003333
.......030110333
.......030110333
......0301111033
......0301111033
.....03011111103
.....03011111103
....030110001110
....030107770110
...0301107270111
...0301072777011
..03011077777011`],
  [ house2, bitmap`
0000000.........
3333330.........
33333330........
33333330........
333333330.......
333333330.......
3333333330......
3333333330......
33333333330.....
33333333330.....
333333333330....
333333333330....
3333333333330...
0333333333330...
03333333333330..
.0333333333330..`],
  [ house3, bitmap`
..03011077777011
.030111000000011
.030111111111111
0301111111111111
0301111110001111
.00111110CCC0111
..011110CCCCC011
..011110CCCCC011
..01110CCCCCCC01
..01110CCCCCCC01
..01110CCCCCCC01
..01110CCCCC0C01
..01110CCCCCCC01
..01110CCCCCCC01
..01110CCCCCCC01
..00000000000000`],
  [ house4, bitmap`
103333333333330.
110333333333330.
1103333333333330
1100000000000000
1101111111111110
1101111111111110
1101100000000110
1101107270770110
1101102770770110
1101100000000110
1101107770770110
1101107770770110
1101100000000110
1101111111111110
1101111111111110
0000000000000000`],
)

setSolids([player, ground])

let level = 1
const levels = [
  map`
............
..c.........
..f.........
.ah.........
.bij........
7v4km.......
8d44n.......
94444oqt....
gggggggggggg
gggggggggggg`,
  map`
............
......c.....
......f.....
.....ah.....
.....bij....
....7v4km...
.2358d44n...
014694444oqt
gggggggggggg
gggggggggggg`,
]

setMap(levels[level])

setBackground(sky);

function hitCheck(somePlayer) {
   if (speed == 1) {
    if (somePlayer.y == getFirst(moblin).y && somePlayer.x == getFirst(moblin).x) {
      somePlayer.remove();
    }
  } else if (speed == 2) {
    if (somePlayer.y == getFirst(lynel).y && somePlayer.x == getFirst(lynel).x) {
      somePlayer.remove();
    }
  } else {
    // do nothing
  }
}

onInput("k", () => {
  if (gameRunning && getFirst(player).y == 7 && canJump && isEndGame) {
    canJump = false;
    inAir = true;
    setTimeout(function(){ inAir = false }, ((500/(speed*multiplier))*3))
    setTimeout(function(){ canJump = true }, (500/(speed*multiplier)))
  }
  else if (gameRunning && getFirst(player).y == 7 && canJump) {
    canJump = false;
    inAir = true;
    setTimeout(function(){ inAir = false }, 500)
    setTimeout(function(){ canJump = true }, (500/(speed*multiplier)))
  } else if (titlescreen) {
    titlescreen = false;
    setMap(levels[0]);
    score = 0;
    isReady = false;
    isJumping = false;
    animCount = 0;
    speed = 1;
    multiplier = 1;
    enemyShouldJump = 20;
    canJump = true;
    inAir = false;
    lastJumped = false;
    isEndGame = false;
    direction = -1;
    addSprite(1, 7, player);
    addSprite(11, 7, moblin);
    gameRunning = true;
  }
});

onInput("j", () => {
  if (gameRunning != true && titlescreen != true) {
    setMap(levels[1]);
    titlescreen = true;
  }
});

function moblinUpdate(somemoblin) {
  if (somemoblin != null) {
    if (gameRunning == true) {
      somemoblin.x -= 1;
      if (enemyShouldJump <= Math.min(Math.max(score/5, 1), 10) && somemoblin.x == 2) {
        somemoblin.y -= 1;
        lastJumped = true;
      }
      if (somemoblin.x == 0 && isReady) {
        isReady = false;
        score += 1;
        updateCastle();
        somemoblin.x += 11;
        somemoblin.y = 7;
        if (lastJumped) {
          enemyShouldJump = 20;
          lastJumped = false;
        } else {
          enemyShouldJump = Math.floor(Math.random()*20);
        }
        if(Math.floor(Math.random() * 10) <= (score/5)) {
          somemoblin.type = lynel;
          speed = 2;
          if (enemyShouldJump <= Math.min(Math.max(score/5, 1), 10)) {
            setLegend([ lynel, bitmap`
.....55557555...
....5255775.....
....72757755....
....777575......
....5777755.....
.222257777.....5
22222577775...55
.222257775555555
....55555555555.
....55555555555.
...55555555555..
..5555555555555.
..55555555555555
...555222222555.
....5........5..
................`]);
            setTimeout((() => {
              setLegend([ lynel, bitmap`
................
....55557555....
...5255775......
..772757755.....
...777575.......
...5777755......
.222257777......
22222577775....5
.222257775555555
....555555555555
....55555555555.
....5555555555..
....5555555555..
.....55555555...
.....55552555...
......555.555...`]);
              setTimeout((() => {setLegend([ lynel, bitmap`
.....33339333...
....3233993.....
....92939933....
....999393......
....3999933.....
.222239999.....3
22222399993...33
.222239993333333
....33333333333.
....33333333333.
...33333333333..
..3333333333333.
..33333333333333
...333222222333.
....3........3..
................`])}), (500/(speed*multiplier)))
            }), (500/(speed*multiplier)))
          }
        } else {
          somemoblin.type = moblin;
          speed = 1;
          if (enemyShouldJump <= Math.min(Math.max(score/5, 1), 10)) {
            setLegend([ moblin, bitmap`
.....55555......
...505555.......
..5035540000....
.003355540000...
.5555555400000..
00535554000000..
550355505540000.
555505505540003.
.55554000555330.
.55555005554000.
..5333335553333.
..5400000540000.
....000000000055
....0000005550..
..554000555555..
...5555..55555..`]);
            setTimeout((() => {
              setLegend([ moblin, bitmap`
................
.....55555......
...505555.......
..5035540000....
.003355540000...
.5555555400000..
00535554000000..
550355500540000.
555505505540003.
.55555055550330.
.55555555400000.
333335555333300.
..5505540000000.
....000554000055
....0555554000..
.....255555.....`]);
              setTimeout((() => {setLegend([ moblin, bitmap`
.....99999......
...939999.......
..9329993333....
.332299993333...
.9999999933333..
33929999333333..
993299939993333.
999939939993332.
.99999333999223.
.99999339999333.
..9222229992222.
..9933333993333.
....333333333399
....3333339993..
..999333999999..
...9999..99999..`])}), (500/(speed*multiplier)))
            }), (500/(speed*multiplier)))
          }
        }
      } else if (somemoblin.x == 0) {
        isReady = true
      }
    } else {
      somemoblin.remove();
    }
  }
}

function updateCastle() {
  if (score == t1) {
    getFirst(bg7).remove();
    getFirst(bg8).remove();
    getFirst(bg9).remove();
    getFirst(bg10).x -= 1;
    getFirst(bg11).x -= 1;
    getFirst(bg12).x -= 1;
    getFirst(bg13).x -= 1;
    getFirst(bg14).x -= 1;
    getFirst(bg15).x -= 1;
    getFirst(bg16).x -= 1;
    getFirst(bg17).x -= 1;
    getFirst(bg18).x -= 1;
    getFirst(bg19).x -= 1;
    getFirst(bg20).x -= 1;
    getFirst(bg21).x -= 1;
    getFirst(bg22).x -= 1;
    getFirst(bg23).x -= 1;
    getFirst(bg24).x -= 1;
  }
  else if (score == t2) {
    getFirst(bg10).remove();
    getFirst(bg11).remove();
    getFirst(bg12).remove();
    getFirst(bg13).remove();
    getAll(bg4).forEach(sprite => { if (sprite.x == 0 && sprite.y == 7) { sprite.remove(); } });
    getFirst(bg14).x -= 1;
    getFirst(bg15).x -= 1;
    getFirst(bg16).x -= 1;
    getFirst(bg17).x -= 1;
    getFirst(bg18).x -= 1;
    getFirst(bg19).x -= 1;
    getFirst(bg20).x -= 1;
    getFirst(bg21).x -= 1;
    getFirst(bg22).x -= 1;
    getFirst(bg23).x -= 1;
    getFirst(bg24).x -= 1;
  }
  else if (score == t3) {
    getFirst(bg14).remove();
    getFirst(bg15).remove();
    getFirst(bg16).remove();
    getFirst(bg17).remove();
    getAll(bg4).forEach(sprite => { if (sprite.x == 0 && sprite.y == 5) { sprite.remove(); } });
    getAll(bg4).forEach(sprite => { if (sprite.x == 0 && sprite.y == 6) { sprite.remove(); } });
    getAll(bg4).forEach(sprite => { if (sprite.x == 0 && sprite.y == 7) { sprite.remove(); } });
    getFirst(bg18).x -= 1;
    getFirst(bg19).x -= 1;
    getFirst(bg20).x -= 1;
    getFirst(bg21).x -= 1;
    getFirst(bg22).x -= 1;
    getFirst(bg23).x -= 1;
    getFirst(bg24).x -= 1;
  }
  else if (score == t4) {
    getFirst(bg18).remove();
    getFirst(bg19).remove();
    getAll(bg4).forEach(sprite => { if (sprite.x == 0 && sprite.y == 5) { sprite.remove(); } });
    getAll(bg4).forEach(sprite => { if (sprite.x == 0 && sprite.y == 6) { sprite.remove(); } });
    getAll(bg4).forEach(sprite => { if (sprite.x == 0 && sprite.y == 7) { sprite.remove(); } });
    getFirst(bg20).x -= 1;
    getFirst(bg21).x -= 1;
    getFirst(bg22).x -= 1;
    getFirst(bg23).x -= 1;
    getFirst(bg24).x -= 1;
  }
  else if (score == t5) {
    getFirst(bg20).remove();
    getFirst(bg21).remove();
    getAll(bg4).forEach(sprite => { if (sprite.x == 0 && sprite.y == 7) { sprite.remove(); } });
    getFirst(bg22).x -= 1;
    getFirst(bg23).x -= 1;
    getFirst(bg24).x -= 1;
  }
  else if (score == t6) {
    getFirst(bg22).remove();
    getFirst(bg23).x -= 1;
    getFirst(bg24).x -= 1;
  }
  else if (score == t7) {
    getFirst(bg23).remove();
    getFirst(bg24).x -= 1;
    addSprite(11, 6, house1);
    addSprite(11, 7, house3);
  }
  else if (score == t8) {
    getFirst(bg24).remove();
    getFirst(house1).x -= 1;
    getFirst(house3).x -= 1;
    addSprite(11, 6, house2);
    addSprite(11, 7, house4);
  }
  else if (score == t9) {
    getFirst(house1).x -= 1;
    getFirst(house2).x -= 1;
    getFirst(house3).x -= 1;
    getFirst(house4).x -= 1;
  }
  if (score >= tm && (score % tm) == 0) {
    getAll(bg4).forEach(obj => {obj.x -= 1});
  }
}

function gameLoop() {
  if (titlescreen) {
    clearText();
    score=0;
    addText("The Legend", {
      x: 5,
      y: 6,
      color: color`2`
    });
    addText("of Zelda:", {
      x: 6,
      y: 7,
      color: color`2`
    });
    addText("Link's Escape", {
      x: 4,
      y: 8,
      color: color`4`
    });
    addText("Press K to begin!", {
      x: 2,
      y: 12,
      color: color`6`
    });
  } else if (getAll(player).length <= 0) {
    gameRunning = false;
    if (getFirst(player) != null) {
      getFirst(player).remove();
    }
    clearText();
    addText("Game Over!\nScore: " + score, {
      x: 5,
      y: 6,
      color: color`6`
    });
    addText("Press J to\nrestart!", {
      x: 5,
      y: 10,
      color: color`2`
    });
  } else if (gameRunning) {
    const p = getFirst(player);
    hitCheck(p);
    clearText();
    if (inAir) {
      p.y = 6;
    } else {
      p.y = 7;
    }
    if (speed == 1) {
      moblinUpdate(getFirst(moblin));
    } else if (speed == 2) {
      moblinUpdate(getFirst(lynel));
    }
    addText("Score: "+score, {
      x: 0,
      y: 0,
      color: color`2`
    });
  
      
    if ((animCount % 2) == 0 && gameRunning) {
      setLegend([ player, bitmap`
  ....00000.......
  ...04442500.....
  ..0442240220....
  .0440440224000..
  0440200224000...
  04402404000.....
  .040220020200...
  ..00220220220...
  ...042022240....
  ...00404440.....
  ...04000000.....
  ..044022040.....
  ..044022020.....
  ..000000040.....
  ...02222000.....
  ..0000000000....` ],
                [ moblin, bitmap`
  .....99999......
  ...939999.......
  ..9329993333....
  .332299993333...
  .9999999933333..
  33929999333333..
  993299939993333.
  999939939993332.
  .99999333999223.
  .99999339999333.
  ..9222229992222.
  ..9933333993333.
  ....333333333399
  ....3333339993..
  ..999333999999..
  ...9999..99999..`],
                [ lynel, bitmap`
  .....33339333...
  ....3233993.....
  ....92939933....
  ....999393......
  ....3999933.....
  .222239999.....3
  22222399993...33
  .222239993333333
  ....33333333333.
  ....33333333333.
  ...33333333333..
  ..3333333333333.
  ..33333333333333
  ...333222222333.
  ....3........3..
  ................`],
                [ ground, bitmap`
  CCC09009CC0090CC
  CCCC009CCCCC0009
  CCCC009CCCCC00C0
  9CCC009CCCCCC0C0
  9CCC09CCCCCCC0C0
  CCCC09CCCCCCCCC0
  CCCC09CCCCC99009
  CCCC09CCCC9CCC09
  CCC009CCCC9CCCC0
  CCC009CCCC9CCCC0
  9C00090CC09CCC00
  9C099900C09CCC09
  C09CCCCC009CCC09
  C09CCCC0009CCC09
  C9CCCCCC000CC000
  09C9CC9090099009`],
                [ bg0, bitmap`
................
................
................
................
................
...............0
.............000
............0000
...........00000
..........000000
........00000000
.......000000000
.....00000000000
...0000000000000
0000000000000000
0000000000000000`],
                [ bg1, bitmap`
              ...0000000000000
              ...0000000000000
              ..00000000000000
              .000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg2, bitmap`
              ................
              ................
              ................
              ...........000..
              ..........00000.
              ..........000000
              ..........000000
              .........0000000
              .........0000000
              ........00000000
              .......000000000
              .......000000000
              ......0000000000
              .....00000000000
              .....00000000000
              ....000000000000`],
                [ bg3, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              0...............
              00..............
              0000............
              000000..........
              00000000........
              0000000000......
              000000000000....
              00000000000000..
              0000000000000000
              0000000000000000`],
                [ bg4, bitmap`
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg5, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ...........00...
              ...........00...
              00........0000..`],
                [ bg6, bitmap`
              000.......00000.
              0000......000000
              00000....0000000
              000000...0000000
              0000000.00000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg7, bitmap`
              ................
              ................
              ................
              .....0..........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.000...00
              ....000.000...00
              ....000.000...00`],
                [ bg8, bitmap`
              ....000.000...00
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ...0000000000000
              ...0000000000000`],
                [ bg9, bitmap`
              ...0000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg10, bitmap`
              ................
              ..............00
              ..............00
              ..............00
              ..............00
              ..............00
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              .............000
              .............000`],
                [ bg11, bitmap`
              .............000
              ...............0
              ...............0
              ...............0
              ................
              ................
              ...0............
              ...0............
              ...0............
              ...0............
              ...0..0..0..0...
              ...0..00.00.00..
              ...0..00.00.00..
              ...0000000000000
              ..00000000000000
              .000000000000000`],
                [ bg12, bitmap`
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              .000000000000000
              .000000000000000
              ..00000000000000
              ..00000000000000
              ..00000000000000
              ..00000000000000
              0.00000000000000
              0.00000000000000
              0.00000000000000`],
                [ bg13, bitmap`
              0.00000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg14, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              .....0..........
              .....0..........
              .....0..........`],
                [ bg15, bitmap`
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ..0000000.......
              ..0000000.......
              ..0000000.......
              ..0000000.......
              ..0000000.......
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....`],
                [ bg16, bitmap`
              00000000000.....
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg17, bitmap`
              00000000000000..
              000000000000....
              000000000000....
              000000000000....
              .000000000......
              .000000000......
              .000000000......
              .000000000......
              .000000000......
              .000000000...0..
              .000000000..00.0
              .000000000..00.0
              .000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg18, bitmap`
              ................
              ................
              ................
              ................
              ................
              ......00........
              ......00........
              ......00........
              ......00........
              0..0..00........
              0.00..00........
              0.00..00........
              00000000........
              000000000.......
              0000000000......
              00000000000.....`],
                [ bg19, bitmap`
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              0000000000......
              0000000000......
              000000000.......
              000000000.......
              000000000.......
              000000000.......
              000000000.000...
              000000000.000...
              000000000.000...
              000000000.000...`],
                [ bg20, bitmap`
              ................
              ................
              ................
              .....0..........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              000.000.........
              000.000.........
              000.000.........
              000.000.........`],
                [ bg21, bitmap`
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.......0.
              00000000......0.
              00000000.....00.
              00000000....0000`],
                [ bg22, bitmap`
              0.............00
              00...........000
              00..........0000
              000....000000000
              0000..0000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg23, bitmap`
              00..............
              000.............
              000.............
              0000............
              00000......00...
              000000....0000..
              000000000000000.
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg24, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              0...............
              00..............
              000.............
              0000............
              00000...........
              00000...........
              000000..........`],
               [ house1, bitmap`
..........000000
.........0333333
.........0333333
........03333333
........03003333
.......030110333
.......030110333
......0301111033
......0301111033
.....03011111103
.....03011111103
....030110001110
....030107770110
...0301107270111
...0301072777011
..03011077777011`],
  [ house2, bitmap`
0000000.........
3333330.........
33333330........
33333330........
333333330.......
333333330.......
3333333330......
3333333330......
33333333330.....
33333333330.....
333333333330....
333333333330....
3333333333330...
0333333333330...
03333333333330..
.0333333333330..`],
  [ house3, bitmap`
..03011077777011
.030111000000011
.030111111111111
0301111111111111
0301111110001111
.00111110CCC0111
..011110CCCCC011
..011110CCCCC011
..01110CCCCCCC01
..01110CCCCCCC01
..01110CCCCCCC01
..01110CCCCC0C01
..01110CCCCCCC01
..01110CCCCCCC01
..01110CCCCCCC01
..00000000000000`],
  [ house4, bitmap`
103333333333330.
110333333333330.
1103333333333330
1100000000000000
1101111111111110
1101111111111110
1101100000000110
1101107270770110
1101102770770110
1101100000000110
1101107770770110
1101107770770110
1101100000000110
1101111111111110
1101111111111110
0000000000000000`],);
    } else if (gameRunning) {
      setLegend([ player, bitmap`
  ................
  ....000000......
  ..0044422500.0..
  .0444224402200..
  .0444044022500..
  .044020022500...
  ..0402404000....
  ..040220020200..
  ...00220220220..
  ....042022240...
  ....00000000....
  ...00440220.....
  ..020440220.....
  ..0200440000....
  ..02200022220...
  .000000000000...` ],
                [ moblin, bitmap`
  ................
  .....99999......
  ...939999.......
  ..9329993333....
  .332299993333...
  .9999999933333..
  33929999333333..
  993299933993333.
  999939939993332.
  .99999399993223.
  .99999999933333.
  222229999222233.
  ..9939993333333.
  ....333999333399
  ....3999999333..
  .....299999.....`],
                [ lynel, bitmap`
  ................
  ....33339333....
  ...3233993......
  ..992939933.....
  ...999393.......
  ...3999933......
  .222239999......
  22222399993....3
  .222239993333333
  ....333333333333
  ....33333333333.
  ....3333333333..
  ....3333333333..
  .....33333333...
  .....33332333...
  ......333.333...`],
                [ ground, bitmap`
  CC0090CCCCCC009C
  CCCC0009CCCC009C
  CCCC00C0CCC09009
  CCCCC0C09CCC009C
  CCCCC0C09CCC09CC
  CCCCCCC0CCCC09CC
  CCC99009CCCC09CC
  CC9CCC09CCCC09CC
  CC9CCCC0CCC009CC
  CC9CCCC0CCC009CC
  C09CCC009C00090C
  C09CCC099C099900
  009CCC09C09CCCCC
  009CCC09C09CCCC0
  000CC000C9CCCCCC
  9009900909C9CC90`],
                [ bg0, bitmap`
................
................
................
................
................
...............0
.............000
............0000
...........00000
..........000000
........00000000
.......000000000
.....00000000000
...0000000000000
0000000000000000
0000000000000000`],
                [ bg1, bitmap`
              ...0000000000000
              ...0000000000000
              ..00000000000000
              .000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg2, bitmap`
              ................
              ................
              ................
              ...........000..
              ..........00000.
              ..........000000
              ..........000000
              .........0000000
              .........0000000
              ........00000000
              .......000000000
              .......000000000
              ......0000000000
              .....00000000000
              .....00000000000
              ....000000000000`],
                [ bg3, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              0...............
              00..............
              0000............
              000000..........
              00000000........
              0000000000......
              000000000000....
              00000000000000..
              0000000000000000
              0000000000000000`],
                [ bg4, bitmap`
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg5, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ...........00...
              ...........00...
              00........0000..`],
                [ bg6, bitmap`
              000.......00000.
              0000......000000
              00000....0000000
              000000...0000000
              0000000.00000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg7, bitmap`
              ................
              ................
              ................
              .....0..........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.000...00
              ....000.000...00
              ....000.000...00`],
                [ bg8, bitmap`
              ....000.000...00
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ...0000000000000
              ...0000000000000`],
                [ bg9, bitmap`
              ...0000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg10, bitmap`
              ................
              ..............00
              ..............00
              ..............00
              ..............00
              ..............00
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              .............000
              .............000`],
                [ bg11, bitmap`
              .............000
              ...............0
              ...............0
              ...............0
              ................
              ................
              ...0............
              ...0............
              ...0............
              ...0............
              ...0..0..0..0...
              ...0..00.00.00..
              ...0..00.00.00..
              ...0000000000000
              ..00000000000000
              .000000000000000`],
                [ bg12, bitmap`
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              .000000000000000
              .000000000000000
              ..00000000000000
              ..00000000000000
              ..00000000000000
              ..00000000000000
              0.00000000000000
              0.00000000000000
              0.00000000000000`],
                [ bg13, bitmap`
              0.00000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg14, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              .....0..........
              .....0..........
              .....0..........`],
                [ bg15, bitmap`
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ..0000000.......
              ..0000000.......
              ..0000000.......
              ..0000000.......
              ..0000000.......
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....`],
                [ bg16, bitmap`
              00000000000.....
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg17, bitmap`
              00000000000000..
              000000000000....
              000000000000....
              000000000000....
              .000000000......
              .000000000......
              .000000000......
              .000000000......
              .000000000......
              .000000000...0..
              .000000000..00.0
              .000000000..00.0
              .000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg18, bitmap`
              ................
              ................
              ................
              ................
              ................
              ......00........
              ......00........
              ......00........
              ......00........
              0..0..00........
              0.00..00........
              0.00..00........
              00000000........
              000000000.......
              0000000000......
              00000000000.....`],
                [ bg19, bitmap`
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              0000000000......
              0000000000......
              000000000.......
              000000000.......
              000000000.......
              000000000.......
              000000000.000...
              000000000.000...
              000000000.000...
              000000000.000...`],
                [ bg20, bitmap`
              ................
              ................
              ................
              .....0..........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              000.000.........
              000.000.........
              000.000.........
              000.000.........`],
                [ bg21, bitmap`
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.......0.
              00000000......0.
              00000000.....00.
              00000000....0000`],
                [ bg22, bitmap`
              0.............00
              00...........000
              00..........0000
              000....000000000
              0000..0000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg23, bitmap`
              00..............
              000.............
              000.............
              0000............
              00000......00...
              000000....0000..
              000000000000000.
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg24, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              0...............
              00..............
              000.............
              0000............
              00000...........
              00000...........
              000000..........`],
               [ house1, bitmap`
..........000000
.........0333333
.........0333333
........03333333
........03003333
.......030110333
.......030110333
......0301111033
......0301111033
.....03011111103
.....03011111103
....030110001110
....030107770110
...0301107270111
...0301072777011
..03011077777011`],
  [ house2, bitmap`
0000000.........
3333330.........
33333330........
33333330........
333333330.......
333333330.......
3333333330......
3333333330......
33333333330.....
33333333330.....
333333333330....
333333333330....
3333333333330...
0333333333330...
03333333333330..
.0333333333330..`],
  [ house3, bitmap`
..03011077777011
.030111000000011
.030111111111111
0301111111111111
0301111110001111
.00111110CCC0111
..011110CCCCC011
..011110CCCCC011
..01110CCCCCCC01
..01110CCCCCCC01
..01110CCCCCCC01
..01110CCCCC0C01
..01110CCCCCCC01
..01110CCCCCCC01
..01110CCCCCCC01
..00000000000000`],
  [ house4, bitmap`
103333333333330.
110333333333330.
1103333333333330
1100000000000000
1101111111111110
1101111111111110
1101100000000110
1101107270770110
1101102770770110
1101100000000110
1101107770770110
1101107770770110
1101100000000110
1101111111111110
1101111111111110
0000000000000000`],);
    }
    animCount++
    multiplier *= 1.0015;

    if (score == (tm+t9)) {
      isEndGame = true;
      endCutscene();
    }
  }
  setTimeout(gameLoop, (400/(speed*multiplier)));
}


function endCutscene() {
  clearTile(11, 7);
  const p = getFirst(player);
  p.y = 7;
  p.x += 1;
  setTimeout(() => {
    p.x += 1;
    setTimeout(() => {
      p.x += 1;
      setTimeout(() => {
        p.x += 1;
        setTimeout(() => {
          p.x += 1;

          setLegend(
            [ house1, bitmap`
.55555...5......
5555555..5......
55555555.55..333
5555555535553333
7575755535555355
..55555535555557
..55555533553357
...5555533353335
...5555533355733
...5555333555557
...5555333555577
...5555335555737
...5555335555737
....553335555773
....553335555533
.....53333553533`],
            [ house2, bitmap`
          0000000.........
          3333330.........
          33333330........
          33333330........
          333333330.......
          333333330.......
          3333333330......
          3333333330......
          33333333330.....
          33333333330.....
          333333333330....
          333333333330....
          3333333333330...
          0333333333330...
          03333333333330..
          .0333333333330..`],
            [ house4, bitmap`
3533335555555...
5533335555555...
3333335555555...
777333555555535.
7335555555555355
7333555555553555
3755555555553555
7755555555535555
735555553335555.
5535555355555533
555355355555333.
555533555533333.
55555553333333..
555555.33333773.
55555.3333333333
......3333333333`],
            [ house3, bitmap`
              ..03011077777011
              .030111000000011
              .030111111111111
              0301111111111111
              0301111110001111
              .00111110CCC0111
              ..011110CCCCC011
              ..011110CCCCC011
              ..01110CCCCCCC01
              ..01110CCCCCCC01
              ..01110CCCCCCC01
              ..01110CCCCC0C01
              ..01110CCCCCCC01
              ..01110CCCCCCC01
              ..01110CCCCCCC01
              ..00000000000000`],
            [ sky, bitmap`
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111`]
          );

          setTimeout(() => {
            
            setLegend(
              [ house1, bitmap`
  ..........000000
  .........0333333
  .........0333333
  ........03333333
  ........03003333
  .......030110333
  .......030110333
  ......0301111033
  ......0301111033
  .....03011111103
  .....03011111103
  ....030110001110
  ....030107770110
  ...0301107270111
  ...0301072777011
  ..03011077777011`],
              [ house2, bitmap`
            0000000.........
            3333330.........
            33333330........
            33333330........
            333333330.......
            333333330.......
            3333333330......
            3333333330......
            33333333330.....
            33333333330.....
            333333333330....
            333333333330....
            3333333333330...
            0333333333330...
            03333333333330..
            .0333333333330..`],
              [ house3, bitmap`
                ..03011077777011
                .030111000000011
                .030111111111111
                0301111111111111
                0301111110001111
                .00111110CCC0111
                ..011110CCCCC011
                ..011110CCCCC011
                ..01110CCCCCCC01
                ..01110CCCCCCC01
                ..01110CCCCCCC01
                ..01110CCCCC0C01
                ..01110CCCCCCC01
                ..01110CCCCCCC01
                ..01110CCCCCCC01
                ..00000000000000`],
              [ house4, bitmap`
                103333333333330.
                110333333333330.
                1103333333333330
                1100000000000000
                1101111111111110
                1101111111111110
                1101100000000110
                1101107270770110
                1101102770770110
                1101100000000110
                1101107770770110
                1101107770770110
                1101100000000110
                1101111111111110
                1101111111111110
                0000000000000000`],
              [ sky, bitmap`
  7777777777777777
  7777777777777777
  7777777777777777
  7777777777777777
  7777777777777777
  7777777777777777
  7777777777777777
  7777777777777777
  7777777777777777
  7777777777777777
  7777777777777777
  7777777777777777
  7777777777777777
  7777777777777777
  7777777777777777
  7777777777777777`]
            );
            
            setTimeout(() => {
              
              setLegend(
                [ house1, bitmap`
    ..........000000
    .........0333333
    .........0333333
    ........03333333
    ........03003333
    .......030110333
    .......030110333
    ......0301111033
    ......0301111033
    .....03011111103
    .....03011111103
    ....030110001110
    ....030107770110
    ...0301107270111
    ...0301072777011
    ..03011077777011`],
                [ house2, bitmap`
    ......5.........
    ......5.........
    333..55.........
    3333555.........
    5535555.........
    755555533.......
    7533553333......
    53375333333.....
    377753333333....
    7555553333333...
    77555533333777..
    7375555335557...
    737555535555....
    3775555355555...
    3355555355555...
    3353553555555...`],
                [ house3, bitmap`
    ......3333333353
    ......3333333355
    ..55553333333333
    .555555333333777
    5555555533337337
    5555555553357337
    5555555555357773
    5555555555555577
    .555555555555577
    3355555555555555
    .333555555555555
    .333335555555555
    ..33333335555555
    .377333333555555
    3333333333.55555
    3333333333......`],
                [ house4, bitmap`
    103333333333330.
    110333333333330.
    1103333333333330
    1100000000000000
    1101111111111110
    1101111111111110
    1101100000000110
    1101107270770110
    1101102770770110
    1101100000000110
    1101107770770110
    1101107770770110
    1101100000000110
    1101111111111110
    1101111111111110
    0000000000000000`],
                [ sky, bitmap`
    1111111111111111
    1111111111111111
    1111111111111111
    1111111111111111
    1111111111111111
    1111111111111111
    1111111111111111
    1111111111111111
    1111111111111111
    1111111111111111
    1111111111111111
    1111111111111111
    1111111111111111
    1111111111111111
    1111111111111111
    1111111111111111`]
              );
              
                setTimeout(() => {
                  
                  setLegend(
                    [ house1, bitmap`
        ..........000000
        .........0333333
        .........0333333
        ........03333333
        ........03003333
        .......030110333
        .......030110333
        ......0301111033
        ......0301111033
        .....03011111103
        .....03011111103
        ....030110001110
        ....030107770110
        ...0301107270111
        ...0301072777011
        ..03011077777011`],
                    [ house2, bitmap`
                  0000000.........
                  3333330.........
                  33333330........
                  33333330........
                  333333330.......
                  333333330.......
                  3333333330......
                  3333333330......
                  33333333330.....
                  33333333330.....
                  333333333330....
                  333333333330....
                  3333333333330...
                  0333333333330...
                  03333333333330..
                  .0333333333330..`],
                    [ house3, bitmap`
                      ..03011077777011
                      .030111000000011
                      .030111111111111
                      0301111111111111
                      0301111110001111
                      .00111110CCC0111
                      ..011110CCCCC011
                      ..011110CCCCC011
                      ..01110CCCCCCC01
                      ..01110CCCCCCC01
                      ..01110CCCCCCC01
                      ..01110CCCCC0C01
                      ..01110CCCCCCC01
                      ..01110CCCCCCC01
                      ..01110CCCCCCC01
                      ..00000000000000`],
                    [ house4, bitmap`
                      103333333333330.
                      110333333333330.
                      1103333333333330
                      1100000000000000
                      1101111111111110
                      1101111111111110
                      1101100000000110
                      1101107270770110
                      1101102770770110
                      1101100000000110
                      1101107770770110
                      1101107770770110
                      1101100000000110
                      1101111111111110
                      1101111111111110
                      0000000000000000`],
                    [ sky, bitmap`
        7777777777777777
        7777777777777777
        7777777777777777
        7777777777777777
        7777777777777777
        7777777777777777
        7777777777777777
        7777777777777777
        7777777777777777
        7777777777777777
        7777777777777777
        7777777777777777
        7777777777777777
        7777777777777777
        7777777777777777
        7777777777777777`]
                  );
                      
                  setTimeout(() => {
                    
                    setLegend(
                      [ house1, bitmap`
      .55555...5......
      5555555..5......
      55555555.55..333
      5555555535553333
      7575755535555355
      ..55555535555557
      ..55555533553357
      ...5555533353335
      ...5555533355733
      ...5555333555557
      ...5555333555577
      ...5555335555737
      ...5555335555737
      ....553335555773
      ....553335555533
      .....53333553533`],
                      [ house2, bitmap`
          ......5.........
          ......5.........
          333..55.........
          3333555.........
          5535555.........
          755555533.......
          7533553333......
          53375333333.....
          377753333333....
          7555553333333...
          77555533333777..
          7375555335557...
          737555535555....
          3775555355555...
          3355555355555...
          3353553555555...`],
                      [ house3, bitmap`
          ......3333333353
          ......3333333355
          ..55553333333333
          .555555333333777
          5555555533337337
          5555555553357337
          5555555555357773
          5555555555555577
          .555555555555577
          3355555555555555
          .333555555555555
          .333335555555555
          ..33333335555555
          .377333333555555
          3333333333.55555
          3333333333......`],
                      [ house4, bitmap`
      3533335555555...
      5533335555555...
      3333335555555...
      777333555555535.
      7335555555555355
      7333555555553555
      3755555555553555
      7755555555535555
      735555553335555.
      5535555355555533
      555355355555333.
      555533555533333.
      55555553333333..
      555555.33333773.
      55555.3333333333
      ......3333333333`],
                      [ sky, bitmap`
          1111111111111111
          1111111111111111
          1111111111111111
          1111111111111111
          1111111111111111
          1111111111111111
          1111111111111111
          1111111111111111
          1111111111111111
          1111111111111111
          1111111111111111
          1111111111111111
          1111111111111111
          1111111111111111
          1111111111111111
          1111111111111111`]
                    );
                    setTimeout(endGame, (400));
                    return
                    
                }, (400))
                    
              }, (400))
              
            }, (400))
            
          }, (400))

          
        }, (400))
        
      }, (400))
      
    }, (400))
    
  }, (400))
}

function gannonUpdate() {
  if (getFirst(house1).x == 0) {
    direction = 1;
    if(getFirst(player).x != 6) {
      getFirst(player).x += 1;
    }
  } else if (getFirst(house2).x == 11) {
    direction = -1;
    if(getFirst(player).x != 5) {
      getFirst(player).x -= 1;
    }
  }
  getFirst(house1).x += 1*direction;
  getFirst(house2).x += 1*direction;
  getFirst(house3).x += 1*direction;
  getFirst(house4).x += 1*direction;
}

function gannonHitCheck(other) {
  let hit = false
  let h1 = getFirst(house1);
  let h2 = getFirst(house2);
  let h3 = getFirst(house3);
  let h4 = getFirst(house4);
  if (other.x == h1.x && other.y == h1.y) {
    other.remove();
    hit = true;
  }
  else if (other.x == h2.x && other.y == h2.y) {
    other.remove();
    hit = true;
  }
  else if (other.x == h3.x && other.y == h3.y) {
    other.remove();
    hit = true;
  }
  else if (other.x == h4.x && other.y == h4.y) {
    other.remove();
    hit = true;
  }
  if (hit) {
    setBackground(sky);
    isEndGame = false;
    gameRunning = false;
      if (getFirst(player) != null) {
        getFirst(player).remove();
      }
      clearText();
      addText("Game Over!\nScore: " + score, {
        x: 5,
        y: 6,
        color: color`6`
      });
      addText("Press J to\nrestart!", {
        x: 5,
        y: 10,
        color: color`2`
      });
    gameLoop();
  }
}

function endGame() {
  if (getAll(player).length <= 0) {
    return;
  }
  else if (isEndGame) {
    const p = getFirst(player);
    gannonUpdate();
    clearText();
    if (inAir) {
      p.y = 5;
    } else {
      p.y = 7;
    }
    score++;
    addText("Score: "+score, {
      x: 0,
      y: 0,
      color: color`2`
    });
    gannonHitCheck(p);
  }

  
  if ((animCount % 2) == 0 && gameRunning) {
      setLegend([ player, bitmap`
  ....00000.......
  ...04442500.....
  ..0442240220....
  .0440440224000..
  0440200224000...
  04402404000.....
  .040220020200...
  ..00220220220...
  ...042022240....
  ...00404440.....
  ...04000000.....
  ..044022040.....
  ..044022020.....
  ..000000040.....
  ...02222000.....
  ..0000000000....` ],
                [ moblin, bitmap`
  .....99999......
  ...939999.......
  ..9329993333....
  .332299993333...
  .9999999933333..
  33929999333333..
  993299939993333.
  999939939993332.
  .99999333999223.
  .99999339999333.
  ..9222229992222.
  ..9933333993333.
  ....333333333399
  ....3333339993..
  ..999333999999..
  ...9999..99999..`],
                [ lynel, bitmap`
  .....33339333...
  ....3233993.....
  ....92939933....
  ....999393......
  ....3999933.....
  .222239999.....3
  22222399993...33
  .222239993333333
  ....33333333333.
  ....33333333333.
  ...33333333333..
  ..3333333333333.
  ..33333333333333
  ...333222222333.
  ....3........3..
  ................`],
                [ ground, bitmap`
  CCC09009CC0090CC
  CCCC009CCCCC0009
  CCCC009CCCCC00C0
  9CCC009CCCCCC0C0
  9CCC09CCCCCCC0C0
  CCCC09CCCCCCCCC0
  CCCC09CCCCC99009
  CCCC09CCCC9CCC09
  CCC009CCCC9CCCC0
  CCC009CCCC9CCCC0
  9C00090CC09CCC00
  9C099900C09CCC09
  C09CCCCC009CCC09
  C09CCCC0009CCC09
  C9CCCCCC000CC000
  09C9CC9090099009`],
                [ bg0, bitmap`
................
................
................
................
................
...............0
.............000
............0000
...........00000
..........000000
........00000000
.......000000000
.....00000000000
...0000000000000
0000000000000000
0000000000000000`],
                [ bg1, bitmap`
              ...0000000000000
              ...0000000000000
              ..00000000000000
              .000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg2, bitmap`
              ................
              ................
              ................
              ...........000..
              ..........00000.
              ..........000000
              ..........000000
              .........0000000
              .........0000000
              ........00000000
              .......000000000
              .......000000000
              ......0000000000
              .....00000000000
              .....00000000000
              ....000000000000`],
                [ bg3, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              0...............
              00..............
              0000............
              000000..........
              00000000........
              0000000000......
              000000000000....
              00000000000000..
              0000000000000000
              0000000000000000`],
                [ bg4, bitmap`
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg5, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ...........00...
              ...........00...
              00........0000..`],
                [ bg6, bitmap`
              000.......00000.
              0000......000000
              00000....0000000
              000000...0000000
              0000000.00000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg7, bitmap`
              ................
              ................
              ................
              .....0..........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.000...00
              ....000.000...00
              ....000.000...00`],
                [ bg8, bitmap`
              ....000.000...00
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ...0000000000000
              ...0000000000000`],
                [ bg9, bitmap`
              ...0000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg10, bitmap`
              ................
              ..............00
              ..............00
              ..............00
              ..............00
              ..............00
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              .............000
              .............000`],
                [ bg11, bitmap`
              .............000
              ...............0
              ...............0
              ...............0
              ................
              ................
              ...0............
              ...0............
              ...0............
              ...0............
              ...0..0..0..0...
              ...0..00.00.00..
              ...0..00.00.00..
              ...0000000000000
              ..00000000000000
              .000000000000000`],
                [ bg12, bitmap`
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              .000000000000000
              .000000000000000
              ..00000000000000
              ..00000000000000
              ..00000000000000
              ..00000000000000
              0.00000000000000
              0.00000000000000
              0.00000000000000`],
                [ bg13, bitmap`
              0.00000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg14, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              .....0..........
              .....0..........
              .....0..........`],
                [ bg15, bitmap`
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ..0000000.......
              ..0000000.......
              ..0000000.......
              ..0000000.......
              ..0000000.......
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....`],
                [ bg16, bitmap`
              00000000000.....
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg17, bitmap`
              00000000000000..
              000000000000....
              000000000000....
              000000000000....
              .000000000......
              .000000000......
              .000000000......
              .000000000......
              .000000000......
              .000000000...0..
              .000000000..00.0
              .000000000..00.0
              .000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg18, bitmap`
              ................
              ................
              ................
              ................
              ................
              ......00........
              ......00........
              ......00........
              ......00........
              0..0..00........
              0.00..00........
              0.00..00........
              00000000........
              000000000.......
              0000000000......
              00000000000.....`],
                [ bg19, bitmap`
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              0000000000......
              0000000000......
              000000000.......
              000000000.......
              000000000.......
              000000000.......
              000000000.000...
              000000000.000...
              000000000.000...
              000000000.000...`],
                [ bg20, bitmap`
              ................
              ................
              ................
              .....0..........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              000.000.........
              000.000.........
              000.000.........
              000.000.........`],
                [ bg21, bitmap`
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.......0.
              00000000......0.
              00000000.....00.
              00000000....0000`],
                [ bg22, bitmap`
              0.............00
              00...........000
              00..........0000
              000....000000000
              0000..0000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg23, bitmap`
              00..............
              000.............
              000.............
              0000............
              00000......00...
              000000....0000..
              000000000000000.
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg24, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              0...............
              00..............
              000.............
              0000............
              00000...........
              00000...........
              000000..........`],
                [ house1, bitmap`
.55555...5......
5555555..5......
55555555.55..333
5555555535553333
7575755535555355
..55555535555557
..55555533553357
...5555533353335
...5555533355733
...5555333555557
...5555333555577
...5555335555737
...5555335555737
....553335555773
....553335555533
.....53333553533`],
                [ house2, bitmap`
    ......5.........
    ......5.........
    333..55.........
    3333555.........
    5535555.........
    755555533.......
    7533553333......
    53375333333.....
    377753333333....
    7555553333333...
    77555533333777..
    7375555335557...
    737555535555....
    3775555355555...
    3355555355555...
    3353553555555...`],
                [ house3, bitmap`
    ......3333333353
    ......3333333355
    ..55553333333333
    .555555333333777
    5555555533337337
    5555555553357337
    5555555555357773
    5555555555555577
    .555555555555577
    3355555555555555
    .333555555555555
    .333335555555555
    ..33333335555555
    .377333333555555
    3333333333.55555
    3333333333......`],
                [ house4, bitmap`
3533335555555...
5533335555555...
3333335555555...
777333555555535.
7335555555555355
7333555555553555
3755555555553555
7755555555535555
735555553335555.
5535555355555533
555355355555333.
555533555533333.
55555553333333..
555555.33333773.
55555.3333333333
......3333333333`],);
    } else if (gameRunning) {
      setLegend([ player, bitmap`
  ................
  ....000000......
  ..0044422500.0..
  .0444224402200..
  .0444044022500..
  .044020022500...
  ..0402404000....
  ..040220020200..
  ...00220220220..
  ....042022240...
  ....00000000....
  ...00440220.....
  ..020440220.....
  ..0200440000....
  ..02200022220...
  .000000000000...` ],
                [ moblin, bitmap`
  ................
  .....99999......
  ...939999.......
  ..9329993333....
  .332299993333...
  .9999999933333..
  33929999333333..
  993299933993333.
  999939939993332.
  .99999399993223.
  .99999999933333.
  222229999222233.
  ..9939993333333.
  ....333999333399
  ....3999999333..
  .....299999.....`],
                [ lynel, bitmap`
  ................
  ....33339333....
  ...3233993......
  ..992939933.....
  ...999393.......
  ...3999933......
  .222239999......
  22222399993....3
  .222239993333333
  ....333333333333
  ....33333333333.
  ....3333333333..
  ....3333333333..
  .....33333333...
  .....33332333...
  ......333.333...`],
                [ ground, bitmap`
  CC0090CCCCCC009C
  CCCC0009CCCC009C
  CCCC00C0CCC09009
  CCCCC0C09CCC009C
  CCCCC0C09CCC09CC
  CCCCCCC0CCCC09CC
  CCC99009CCCC09CC
  CC9CCC09CCCC09CC
  CC9CCCC0CCC009CC
  CC9CCCC0CCC009CC
  C09CCC009C00090C
  C09CCC099C099900
  009CCC09C09CCCCC
  009CCC09C09CCCC0
  000CC000C9CCCCCC
  9009900909C9CC90`],
                [ bg0, bitmap`
................
................
................
................
................
...............0
.............000
............0000
...........00000
..........000000
........00000000
.......000000000
.....00000000000
...0000000000000
0000000000000000
0000000000000000`],
                [ bg1, bitmap`
              ...0000000000000
              ...0000000000000
              ..00000000000000
              .000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg2, bitmap`
              ................
              ................
              ................
              ...........000..
              ..........00000.
              ..........000000
              ..........000000
              .........0000000
              .........0000000
              ........00000000
              .......000000000
              .......000000000
              ......0000000000
              .....00000000000
              .....00000000000
              ....000000000000`],
                [ bg3, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              0...............
              00..............
              0000............
              000000..........
              00000000........
              0000000000......
              000000000000....
              00000000000000..
              0000000000000000
              0000000000000000`],
                [ bg4, bitmap`
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg5, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ...........00...
              ...........00...
              00........0000..`],
                [ bg6, bitmap`
              000.......00000.
              0000......000000
              00000....0000000
              000000...0000000
              0000000.00000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg7, bitmap`
              ................
              ................
              ................
              .....0..........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.000...00
              ....000.000...00
              ....000.000...00`],
                [ bg8, bitmap`
              ....000.000...00
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ...0000000000000
              ...0000000000000`],
                [ bg9, bitmap`
              ...0000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg10, bitmap`
              ................
              ..............00
              ..............00
              ..............00
              ..............00
              ..............00
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              .............000
              .............000`],
                [ bg11, bitmap`
              .............000
              ...............0
              ...............0
              ...............0
              ................
              ................
              ...0............
              ...0............
              ...0............
              ...0............
              ...0..0..0..0...
              ...0..00.00.00..
              ...0..00.00.00..
              ...0000000000000
              ..00000000000000
              .000000000000000`],
                [ bg12, bitmap`
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              .000000000000000
              .000000000000000
              ..00000000000000
              ..00000000000000
              ..00000000000000
              ..00000000000000
              0.00000000000000
              0.00000000000000
              0.00000000000000`],
                [ bg13, bitmap`
              0.00000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg14, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              .....0..........
              .....0..........
              .....0..........`],
                [ bg15, bitmap`
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ..0000000.......
              ..0000000.......
              ..0000000.......
              ..0000000.......
              ..0000000.......
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....`],
                [ bg16, bitmap`
              00000000000.....
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg17, bitmap`
              00000000000000..
              000000000000....
              000000000000....
              000000000000....
              .000000000......
              .000000000......
              .000000000......
              .000000000......
              .000000000......
              .000000000...0..
              .000000000..00.0
              .000000000..00.0
              .000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg18, bitmap`
              ................
              ................
              ................
              ................
              ................
              ......00........
              ......00........
              ......00........
              ......00........
              0..0..00........
              0.00..00........
              0.00..00........
              00000000........
              000000000.......
              0000000000......
              00000000000.....`],
                [ bg19, bitmap`
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              0000000000......
              0000000000......
              000000000.......
              000000000.......
              000000000.......
              000000000.......
              000000000.000...
              000000000.000...
              000000000.000...
              000000000.000...`],
                [ bg20, bitmap`
              ................
              ................
              ................
              .....0..........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              000.000.........
              000.000.........
              000.000.........
              000.000.........`],
                [ bg21, bitmap`
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.......0.
              00000000......0.
              00000000.....00.
              00000000....0000`],
                [ bg22, bitmap`
              0.............00
              00...........000
              00..........0000
              000....000000000
              0000..0000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg23, bitmap`
              00..............
              000.............
              000.............
              0000............
              00000......00...
              000000....0000..
              000000000000000.
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg24, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              0...............
              00..............
              000.............
              0000............
              00000...........
              00000...........
              000000..........`],
                [ house2, bitmap`
......5...55555.
......5..5555555
333..55.55555555
3333555355555555
5535555355575757
75555553555555..
75335533555555..
5333533355555...
3375533355555...
7555553335555...
7755553335555...
7375555335555...
7375555335555...
377555533355....
335555533355....
33535533335.....`],
                [ house1, bitmap`
.........5......
.........5......
.........55..333
.........5553333
.........5555355
.......335555557
......3333553357
.....33333357335
....333333357773
...3333333555557
..77733333555577
...7555335555737
....555535555737
...5555535555773
...5555535555533
...5555553553533`],
                [ house4, bitmap`
3533333333......
5533333333......
33333333335555..
777333333555555.
7337333355555555
7337533555555555
3777535555555555
7755555555555555
775555555555555.
5555555555555533
555555555555333.
555555555533333.
55555553333333..
555555333333773.
55555.3333333333
......3333333333`],
                [ house3, bitmap`
...5555555333353
...5555555333355
...5555555333333
.535555555333777
5535555555555337
5553555555553337
5553555555555573
5555355555555577
.555533355555537
3355555535555355
.333555553553555
.333335555335555
..33333335555555
.37733333.555555
3333333333.55555
3333333333......`],);
    }
    if ((animCount % 2) == 0 && gameRunning && direction == -1) {
      setLegend([ player, bitmap`
.......00000....
.....00524440...
....0220422440..
..0004220440440.
...0004220020440
.....00040420440
...002020022040.
...02202202200..
....042220240...
.....04440400...
.....00000040...
.....040220440..
.....020220440..
.....040000000..
.....00022220...
....0000000000..` ],
                [ moblin, bitmap`
  .....99999......
  ...939999.......
  ..9329993333....
  .332299993333...
  .9999999933333..
  33929999333333..
  993299939993333.
  999939939993332.
  .99999333999223.
  .99999339999333.
  ..9222229992222.
  ..9933333993333.
  ....333333333399
  ....3333339993..
  ..999333999999..
  ...9999..99999..`],
                [ lynel, bitmap`
  .....33339333...
  ....3233993.....
  ....92939933....
  ....999393......
  ....3999933.....
  .222239999.....3
  22222399993...33
  .222239993333333
  ....33333333333.
  ....33333333333.
  ...33333333333..
  ..3333333333333.
  ..33333333333333
  ...333222222333.
  ....3........3..
  ................`],
                [ ground, bitmap`
  CCC09009CC0090CC
  CCCC009CCCCC0009
  CCCC009CCCCC00C0
  9CCC009CCCCCC0C0
  9CCC09CCCCCCC0C0
  CCCC09CCCCCCCCC0
  CCCC09CCCCC99009
  CCCC09CCCC9CCC09
  CCC009CCCC9CCCC0
  CCC009CCCC9CCCC0
  9C00090CC09CCC00
  9C099900C09CCC09
  C09CCCCC009CCC09
  C09CCCC0009CCC09
  C9CCCCCC000CC000
  09C9CC9090099009`],
                [ bg0, bitmap`
................
................
................
................
................
...............0
.............000
............0000
...........00000
..........000000
........00000000
.......000000000
.....00000000000
...0000000000000
0000000000000000
0000000000000000`],
                [ bg1, bitmap`
              ...0000000000000
              ...0000000000000
              ..00000000000000
              .000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg2, bitmap`
              ................
              ................
              ................
              ...........000..
              ..........00000.
              ..........000000
              ..........000000
              .........0000000
              .........0000000
              ........00000000
              .......000000000
              .......000000000
              ......0000000000
              .....00000000000
              .....00000000000
              ....000000000000`],
                [ bg3, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              0...............
              00..............
              0000............
              000000..........
              00000000........
              0000000000......
              000000000000....
              00000000000000..
              0000000000000000
              0000000000000000`],
                [ bg4, bitmap`
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg5, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ...........00...
              ...........00...
              00........0000..`],
                [ bg6, bitmap`
              000.......00000.
              0000......000000
              00000....0000000
              000000...0000000
              0000000.00000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg7, bitmap`
              ................
              ................
              ................
              .....0..........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.000...00
              ....000.000...00
              ....000.000...00`],
                [ bg8, bitmap`
              ....000.000...00
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ...0000000000000
              ...0000000000000`],
                [ bg9, bitmap`
              ...0000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg10, bitmap`
              ................
              ..............00
              ..............00
              ..............00
              ..............00
              ..............00
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              .............000
              .............000`],
                [ bg11, bitmap`
              .............000
              ...............0
              ...............0
              ...............0
              ................
              ................
              ...0............
              ...0............
              ...0............
              ...0............
              ...0..0..0..0...
              ...0..00.00.00..
              ...0..00.00.00..
              ...0000000000000
              ..00000000000000
              .000000000000000`],
                [ bg12, bitmap`
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              .000000000000000
              .000000000000000
              ..00000000000000
              ..00000000000000
              ..00000000000000
              ..00000000000000
              0.00000000000000
              0.00000000000000
              0.00000000000000`],
                [ bg13, bitmap`
              0.00000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg14, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              .....0..........
              .....0..........
              .....0..........`],
                [ bg15, bitmap`
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ..0000000.......
              ..0000000.......
              ..0000000.......
              ..0000000.......
              ..0000000.......
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....`],
                [ bg16, bitmap`
              00000000000.....
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg17, bitmap`
              00000000000000..
              000000000000....
              000000000000....
              000000000000....
              .000000000......
              .000000000......
              .000000000......
              .000000000......
              .000000000......
              .000000000...0..
              .000000000..00.0
              .000000000..00.0
              .000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg18, bitmap`
              ................
              ................
              ................
              ................
              ................
              ......00........
              ......00........
              ......00........
              ......00........
              0..0..00........
              0.00..00........
              0.00..00........
              00000000........
              000000000.......
              0000000000......
              00000000000.....`],
                [ bg19, bitmap`
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              0000000000......
              0000000000......
              000000000.......
              000000000.......
              000000000.......
              000000000.......
              000000000.000...
              000000000.000...
              000000000.000...
              000000000.000...`],
                [ bg20, bitmap`
              ................
              ................
              ................
              .....0..........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              000.000.........
              000.000.........
              000.000.........
              000.000.........`],
                [ bg21, bitmap`
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.......0.
              00000000......0.
              00000000.....00.
              00000000....0000`],
                [ bg22, bitmap`
              0.............00
              00...........000
              00..........0000
              000....000000000
              0000..0000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg23, bitmap`
              00..............
              000.............
              000.............
              0000............
              00000......00...
              000000....0000..
              000000000000000.
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg24, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              0...............
              00..............
              000.............
              0000............
              00000...........
              00000...........
              000000..........`],
                [ house1, bitmap`
.55555...5......
5555555..5......
55555555.55..333
5555555535553333
7575755535555355
..55555535555557
..55555533553357
...5555533353335
...5555533355733
...5555333555557
...5555333555577
...5555335555737
...5555335555737
....553335555773
....553335555533
.....53333553533`],
                [ house2, bitmap`
    ......5.........
    ......5.........
    333..55.........
    3333555.........
    5535555.........
    755555533.......
    7533553333......
    53375333333.....
    377753333333....
    7555553333333...
    77555533333777..
    7375555335557...
    737555535555....
    3775555355555...
    3355555355555...
    3353553555555...`],
                [ house3, bitmap`
    ......3333333353
    ......3333333355
    ..55553333333333
    .555555333333777
    5555555533337337
    5555555553357337
    5555555555357773
    5555555555555577
    .555555555555577
    3355555555555555
    .333555555555555
    .333335555555555
    ..33333335555555
    .377333333555555
    3333333333.55555
    3333333333......`],
                [ house4, bitmap`
3533335555555...
5533335555555...
3333335555555...
777333555555535.
7335555555555355
7333555555553555
3755555555553555
7755555555535555
735555553335555.
5535555355555533
555355355555333.
555533555533333.
55555553333333..
555555.33333773.
55555.3333333333
......3333333333`],);
    } else if (gameRunning && direction == -1) {
      setLegend([ player, bitmap`
................
......000000....
..0.0052244400..
..0022044224440.
..0052204404440.
...005220020440.
....0004042040..
..002020022040..
..02202202200...
...042220240....
....00000000....
.....02204400...
.....022044020..
....0000440020..
...02222000220..
...000000000000.` ],
                [ moblin, bitmap`
  ................
  .....99999......
  ...939999.......
  ..9329993333....
  .332299993333...
  .9999999933333..
  33929999333333..
  993299933993333.
  999939939993332.
  .99999399993223.
  .99999999933333.
  222229999222233.
  ..9939993333333.
  ....333999333399
  ....3999999333..
  .....299999.....`],
                [ lynel, bitmap`
  ................
  ....33339333....
  ...3233993......
  ..992939933.....
  ...999393.......
  ...3999933......
  .222239999......
  22222399993....3
  .222239993333333
  ....333333333333
  ....33333333333.
  ....3333333333..
  ....3333333333..
  .....33333333...
  .....33332333...
  ......333.333...`],
                [ ground, bitmap`
  CC0090CCCCCC009C
  CCCC0009CCCC009C
  CCCC00C0CCC09009
  CCCCC0C09CCC009C
  CCCCC0C09CCC09CC
  CCCCCCC0CCCC09CC
  CCC99009CCCC09CC
  CC9CCC09CCCC09CC
  CC9CCCC0CCC009CC
  CC9CCCC0CCC009CC
  C09CCC009C00090C
  C09CCC099C099900
  009CCC09C09CCCCC
  009CCC09C09CCCC0
  000CC000C9CCCCCC
  9009900909C9CC90`],
                [ bg0, bitmap`
................
................
................
................
................
...............0
.............000
............0000
...........00000
..........000000
........00000000
.......000000000
.....00000000000
...0000000000000
0000000000000000
0000000000000000`],
                [ bg1, bitmap`
              ...0000000000000
              ...0000000000000
              ..00000000000000
              .000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg2, bitmap`
              ................
              ................
              ................
              ...........000..
              ..........00000.
              ..........000000
              ..........000000
              .........0000000
              .........0000000
              ........00000000
              .......000000000
              .......000000000
              ......0000000000
              .....00000000000
              .....00000000000
              ....000000000000`],
                [ bg3, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              0...............
              00..............
              0000............
              000000..........
              00000000........
              0000000000......
              000000000000....
              00000000000000..
              0000000000000000
              0000000000000000`],
                [ bg4, bitmap`
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg5, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ...........00...
              ...........00...
              00........0000..`],
                [ bg6, bitmap`
              000.......00000.
              0000......000000
              00000....0000000
              000000...0000000
              0000000.00000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg7, bitmap`
              ................
              ................
              ................
              .....0..........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.000...00
              ....000.000...00
              ....000.000...00`],
                [ bg8, bitmap`
              ....000.000...00
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ....000000000000
              ...0000000000000
              ...0000000000000`],
                [ bg9, bitmap`
              ...0000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg10, bitmap`
              ................
              ..............00
              ..............00
              ..............00
              ..............00
              ..............00
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              ...........00000
              .............000
              .............000`],
                [ bg11, bitmap`
              .............000
              ...............0
              ...............0
              ...............0
              ................
              ................
              ...0............
              ...0............
              ...0............
              ...0............
              ...0..0..0..0...
              ...0..00.00.00..
              ...0..00.00.00..
              ...0000000000000
              ..00000000000000
              .000000000000000`],
                [ bg12, bitmap`
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              .000000000000000
              .000000000000000
              ..00000000000000
              ..00000000000000
              ..00000000000000
              ..00000000000000
              0.00000000000000
              0.00000000000000
              0.00000000000000`],
                [ bg13, bitmap`
              0.00000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg14, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              .....0..........
              .....0..........
              .....0..........`],
                [ bg15, bitmap`
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ..0000000.......
              ..0000000.......
              ..0000000.......
              ..0000000.......
              ..0000000.......
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....`],
                [ bg16, bitmap`
              00000000000.....
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000...
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg17, bitmap`
              00000000000000..
              000000000000....
              000000000000....
              000000000000....
              .000000000......
              .000000000......
              .000000000......
              .000000000......
              .000000000......
              .000000000...0..
              .000000000..00.0
              .000000000..00.0
              .000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg18, bitmap`
              ................
              ................
              ................
              ................
              ................
              ......00........
              ......00........
              ......00........
              ......00........
              0..0..00........
              0.00..00........
              0.00..00........
              00000000........
              000000000.......
              0000000000......
              00000000000.....`],
                [ bg19, bitmap`
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              00000000000.....
              0000000000......
              0000000000......
              000000000.......
              000000000.......
              000000000.......
              000000000.......
              000000000.000...
              000000000.000...
              000000000.000...
              000000000.000...`],
                [ bg20, bitmap`
              ................
              ................
              ................
              .....0..........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              ....000.........
              000.000.........
              000.000.........
              000.000.........
              000.000.........`],
                [ bg21, bitmap`
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.........
              0000000.......0.
              00000000......0.
              00000000.....00.
              00000000....0000`],
                [ bg22, bitmap`
              0.............00
              00...........000
              00..........0000
              000....000000000
              0000..0000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg23, bitmap`
              00..............
              000.............
              000.............
              0000............
              00000......00...
              000000....0000..
              000000000000000.
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000
              0000000000000000`],
                [ bg24, bitmap`
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              ................
              0...............
              00..............
              000.............
              0000............
              00000...........
              00000...........
              000000..........`],
                [ house2, bitmap`
......5...55555.
......5..5555555
333..55.55555555
3333555355555555
5535555355575757
75555553555555..
75335533555555..
5333533355555...
3375533355555...
7555553335555...
7755553335555...
7375555335555...
7375555335555...
377555533355....
335555533355....
33535533335.....`],
                [ house1, bitmap`
.........5......
.........5......
.........55..333
.........5553333
.........5555355
.......335555557
......3333553357
.....33333357335
....333333357773
...3333333555557
..77733333555577
...7555335555737
....555535555737
...5555535555773
...5555535555533
...5555553553533`],
                [ house4, bitmap`
3533333333......
5533333333......
33333333335555..
777333333555555.
7337333355555555
7337533555555555
3777535555555555
7755555555555555
775555555555555.
5555555555555533
555555555555333.
555555555533333.
55555553333333..
555555333333773.
55555.3333333333
......3333333333`],
                [ house3, bitmap`
...5555555333353
...5555555333355
...5555555333333
.535555555333777
5535555555555337
5553555555553337
5553555555555573
5555355555555577
.555533355555537
3355555535555355
.333555553553555
.333335555335555
..33333335555555
.37733333.555555
3333333333.55555
3333333333......`],);
    }
    animCount++
    multiplier *= 1.005;

  setTimeout(endGame, (500/(speed*multiplier)));
}


playMusic();
gameLoop();
